package com.dek.seckill.common.util;

import java.util.Objects;

public class CodeMsg {

    private int code;
    private String msg;

    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500, "error");
    public static CodeMsg PARAMS_ERROR = new CodeMsg(400, "参数校验异常：%s");


    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public CodeMsg fillArgs(Object... args) {
        Objects.requireNonNull(this.msg, "CodeMsg 消息体不能为空");
        this.msg = String.format(this.msg, args);
        return this;
    }

}
